<%@ Page language="vb" CodeFile="addDriver.aspx.vb" Inherits="addDriver_aspx_vb" %>

<%
    rowNumber = 0
    If (Request.QueryString("do")) = Nothing Then 
        subDo = Request.QueryString("subDo")
        intClientID = Request.QueryString("clientID")
        intClientID = CLng(intClientID)
        dbOpen()
        RecSet = Conn.Execute("Select client From tblClient Where clientID = " & intClientID & "")
        If RecSet.EOF Then 
            Response.Redirect("searchDriver.aspx")
        Else
            client = RecSet.Fields("client").Value
        End IF
        RecSet.Close()
        RecSet = Nothing
        dbClose()
        Over()
        strJS = ""
        strJS = strJS + "[""driver"", ""==''""]"
        checkFields()
        Response.Write("<table cellpadding='0' cellspacing='0' border='0' width='1000'>")
        Response.Write("<tr>")
        Response.Write("<td valign='top'>")
        Response.Write("<table cellpadding='2' cellspacing='2' width='450'>")
        Response.Write("<tr><td class='headline' colspan='3'>ADD DRIVER<font color='#fcbc00'>" & subDo & "</font><hr class='hrHeadline'></td></tr>")
        Response.Write("<form action='addDriver.aspx?do=save&clientID=" & intClientID & "' method='post' onsubmit=""javascript:return checkFields();"">")
        Response.Write("<tr><td class='formBold'>Lease taker:</td><td align='right'><input type='text' name='client' id='client' value='" & client & "' size='40' maxlength='50' readonly='readonly'></td></tr>")
        Response.Write("<tr><td class='formBold'>Driver:</td><td align='right'><input type='text' name='driver' id='driver' size='40' maxlength='50'></td><td><div id='error_driver' class='edit_error'>&laquo; OBS!</div></td></tr>")
        Response.Write("<tr><td class='formBold'>Street:</td><td align='right'><input type='text' name='street' id='street' size='40' maxlength='50'></td></tr>")
        Response.Write("<tr><td class='formBold'>Zipcode:</td><td align='right'><input type='text' name='zipcode' id='zipcode' size='40' maxlength='50' onkeyup='re=/(\d*)/; re.exec(this.value); this.value=RegExp.$1;'></td></tr>")
        Response.Write("<tr><td class='formBold'>City:</td><td align='right'><input type='text' name='city' id='city' size='40' maxlength='50'></td></tr>")
        Response.Write("<tr><td class='formBold'>Areacode:</td><td align='right'><input type='text' name='areacode' id='areacode' size='40' maxlength='50' onkeyup='re=/(\d*)/; re.exec(this.value); this.value=RegExp.$1;'></td></tr>")
        Response.Write("<tr><td class='formBold'>Telephone:</td><td align='right'><input type='text' name='telephone' id='telephone' size='40' maxlength='50' onkeyup='re=/(\d*)/; re.exec(this.value); this.value=RegExp.$1;'></td></tr>")
        Response.Write("<tr><td class='formBold'>Email:</td><td align='right'><input type='text' name='email' id='email' size='40' maxlength='50'></td></tr>")
        Response.Write("<tr><td align='right' colspan='2'><input type='submit' value='Save'></td></tr>")
        Response.Write("</form>")
        Response.Write("<tr><td colspan='3'><hr class='hrHeadline'></td></tr>")
        Response.Write("</table>")
        Response.Write("</td>")
        Response.Write("<td width='100'></td>")
        Response.Write("<td valign='top'>")
        Response.Write("<table cellpadding='2' cellspacing='2' width='450'>")
        Response.Write("<tr><td class='headline' colspan='2'>CURRENT DRIVERS<hr class='hrHeadline'></td></tr>")
        dbOpen()
        RecSet = Conn.Execute("Select driverID, driver From tblDriver Where clientID = " & intClientID & "")
        If RecSet.EOF Then 
            Response.Write("<tr><td><font color='red'>No drivers saved</font></td></tr>")
        Else
            Do Until RecSet.EOF
                driverID = RecSet.Fields("driverID").Value
                driver = RecSet.Fields("driver").Value
                If rowNumber = 0 Then 
                    strGrey = " bgcolor='#eeeeee'"
                    rowNumber = 1
                Else
                    strGrey = ""
                    rowNumber = 0
                End IF
                Response.Write("<tr" & strGrey & ">")
                Response.Write("<td>" & driver & "</td>")
                Response.Write("<td align='right'><a href='editDriver.aspx?driverID=" & driverID & "'>edit driver</a></td>")
                Response.Write("</tr>")
                RecSet.MoveNext()
            Loop
        End IF
        RecSet.Close()
        RecSet = Nothing
        dbClose()
        Response.Write("<tr><td colspan='2'><hr class='hrHeadline'></td></tr>")
        Response.Write("</table>")
        Response.Write("</td>")
        Response.Write("</tr>")
        Response.Write("</table>")
        Under()
    ElseIf Request.QueryString("do") = "save" Then 
        intClientID = Request.QueryString("clientID")
        intClientID = CLng(intClientID)
        driver = Request.Form("driver")
        street = Request.Form("street")
        zipcode = Request.Form("zipcode")
        city = Request.Form("city")
        areacode = Request.Form("areaCode")
        telephone = Request.Form("telephone")
        email = Request.Form("email")
        userID = fragusLeasingUserID
        dbOpen()
        RecSet = Conn.Execute("Select countryID From tblClient Where clientID = " & intClientID & "")
        If RecSet.EOF Then 
            'Response.Redirect "searchDriver.aspx"
            Response.Write("neeeeeeeeeej")
        Else
            countryID = RecSet.Fields("countryID").Value
        End IF
        RecSet.Close()
        RecSet = Nothing
        dbClose()
        If Len(driver) > 0 Then 
            driver = Trim(driver)
            driver = Replace(CStr(driver), "'", "")
            driver = Replace(CStr(driver), """", "")
            driver = Replace(CStr(driver), "<", "")
            driver = Replace(CStr(driver), ">", "")
            driver = Replace(CStr(driver), "=", "")
        End IF
        If Len(street) > 0 Then 
            street = Trim(street)
            street = Replace(street, "'", "")
            street = Replace(street, """", "")
            street = Replace(street, "<", "")
            street = Replace(street, ">", "")
            street = Replace(street, "=", "")
        End IF
        If Len(zipcode) > 0 Then 
            zipcode = Trim(zipcode)
            zipcode = Replace(zipcode, "'", "")
            zipcode = Replace(zipcode, """", "")
            zipcode = Replace(zipcode, "<", "")
            zipcode = Replace(zipcode, ">", "")
            zipcode = Replace(zipcode, "=", "")
        End IF
        If Len(city) > 0 Then 
            city = Trim(city)
            city = Replace(city, "'", "")
            city = Replace(city, """", "")
            city = Replace(city, "<", "")
            city = Replace(city, ">", "")
            city = Replace(city, "=", "")
        End IF
        If Len(areacode) > 0 Then 
            areacode = Trim(areacode)
            areacode = Replace(areacode, "'", "")
            areacode = Replace(areacode, """", "")
            areacode = Replace(areacode, "<", "")
            areacode = Replace(areacode, ">", "")
            areacode = Replace(areacode, "=", "")
        End IF
        If Len(telephone) > 0 Then 
            telephone = Trim(telephone)
            telephone = Replace(telephone, "'", "")
            telephone = Replace(telephone, """", "")
            telephone = Replace(telephone, "<", "")
            telephone = Replace(telephone, ">", "")
            telephone = Replace(telephone, "=", "")
        End IF
        If Len(email) > 0 Then 
            email = Trim(email)
            email = Replace(email, "'", "")
            email = Replace(email, """", "")
            email = Replace(email, "<", "")
            email = Replace(email, ">", "")
            email = Replace(email, "=", "")
        End IF
        dbOpen()
        Conn.Execute("Insert Into tblDriver (clientID, userID, countryID, driver, street, zipcode, city, areacode, telephone, email) Values(" & intClientID & "," & userID & "," & countryID & ",'" & driver & "','" & street & "','" & zipcode & "','" & city & "','" & areacode & "','" & telephone & "','" & email & "')")
        dbClose()
        Response.Redirect("addDriver.aspx?clientID=" & intClientID & "&subDo=%20-%20SAVED")
    End IF
%>
